package ljl.codetop300;

import commons.TreeNode;

import java.util.LinkedList;

public class _144_mirror_tree {

  static class test {
    public TreeNode mirrorTree(TreeNode root) {
      if (root == null) return null;
      TreeNode tmp = mirrorTree(root.left);
      root.left = mirrorTree(root.right);
      root.right = tmp;
      return root;
    }
  }

  static class iter {
    public TreeNode mirrorTree(TreeNode root) {
      if (root == null) return null;
      LinkedList<TreeNode> stack = new LinkedList<>();
      stack.push(root);
      while (!stack.isEmpty()) {
        TreeNode node = stack.pop();
        if (node.left != null) stack.push(node.left);
        if (node.right != null) stack.push(node.right);
        TreeNode t = node.left;
        node.left = node.right;
        node.right = t;
      }
      return root;
    }
  }
}
